import { Component } from '@angular/core';
import { ModalService, ConfirmService, Pagination } from 'ng-tui';
import { InventoryService } from '../../services/inventory.service';
import { Inventory } from '../../interfaces/inventory.interfaces';
import { ApiData, SearchParams } from '../../../../cores/classes';
import { RequestService, GlobalService } from '../../../../cores/services';
@Component({
    template: `
    <div class="modal-header">
    <h5 class="modal-title">添加资产</h5>
    <button (click)="close()" type="button" class="close">
        <span aria-hidden="true">&times;</span>
    </button>
    </div>
    <ts-datepicker #datepickerone="tsDatepicker"
    [(ngModel)]="inventory.beginOfPeriodDate" [color]="global.params.color" name="couponName"></ts-datepicker>
    <ts-datepicker #datepicker="tsDatepicker" [(ngModel)]="inventory.buyTime"
     [color]="global.params.color" name="couponName"></ts-datepicker>
    <div class="modal-body">
        <div style="flex: 1 1 auto;padding: 1.25rem 0rem 1.25rem 0rem;">
            <div class="form-group row" style="display:flex;">
                <label class="col-sm-2 col-form-label label-required text-right" style="padding-right: 0px;">资产名称</label>
                <div class="col-sm-4">
                    <input type="text" [(ngModel)]="inventory.assetName" class="form-control">
                </div>
                <label class="col-sm-2 col-form-label label-required text-right" style="padding-right: 0px;">资产类型</label>
                <div class="col-sm-4">
                    <input type="text" [(ngModel)]="inventory.assetType" class="form-control">
                </div>
            </div>
            <div class="form-group row" style="display:flex;">
                <label class="col-sm-2 col-form-label label-required text-right" style="padding-right: 0px;">购买时间</label>
                <div class="col-sm-4">
                    <input tsToggle [target]="datepicker" [bind]="datepicker"
                     [value]="inventory.buyTime " placeholder="请选择日期" type="text" class="form-control ht bg-white pointer required">
                </div>
                <label class="col-sm-2 col-form-label label-required text-right" style="padding-right: 0px;">采购金额</label>
                <div class="col-sm-4">
                    <input type="text" [(ngModel)]="inventory.purchaseMoney" class="form-control">
                </div>
            </div>
            <div class="form-group row" style="display:flex;">
                <label class="col-sm-2 col-form-label label-required text-right" style="padding-right: 0px;">可用年限</label>
                <div class="col-sm-4">
                    <input type="text" [(ngModel)]="inventory.usefulYears" class="form-control">
                </div>
                <label class="col-sm-2 col-form-label label-required text-right" style="padding-right: 0px;">已用年限</label>
                <div class="col-sm-4">
                    <input type="text" [(ngModel)]="inventory.haveUsedYeas" class="form-control">
                </div>
            </div>
            <div class="form-group row">
                <label class="col-sm-2 col-form-label label-required text-right" style="padding-right: 0px;">折旧方式</label>
                <div class="col-sm-4">
                    <input type="text" [(ngModel)]="inventory.depreciationWay" class="form-control">
                </div>
                <label class="col-sm-2 col-form-label label-required text-right" style="padding-right: 0px;">剩余价值</label>
                <div class="col-sm-4">
                    <input type="text" [(ngModel)]="inventory.surplusValue" class="form-control">
                </div>
            </div>
            <div class="form-group row">
                <label class="col-sm-2 col-form-label label-required text-right" style="padding-right: 0px;">期初日期</label>
                <div class="col-sm-4">
                    <input tsToggle [target]="datepickerone"
                     [bind]="datepickerone" [value]="inventory.beginOfPeriodDate " placeholder="请选择日期"
                        type="text" class="form-control ht bg-white pointer required">
                </div>
                <label class="col-sm-2 col-form-label label-required text-right" style="padding-right: 0px;">资产编号</label>
                <div class="col-sm-4">
                    <input type="text" class="form-control">
                </div>
            </div>
        </div>
    </div>
    <div class="modal-footer">
        <button tsBtn (click)="modal.dismiss()">取消</button>
        <button tsBtn loading color="success" (submit)="confirmSave($event)">保存</button>
    </div>`,
})
export class ModalAccontComponent {
    // name="couponName"[(ngModel)]="voucher.couponName"
    // content = '...';
    inventory: Inventory = { id: 0, beginOfPeriodDate: '' };
    changg: number;
    loading = false;
    search = new SearchParams({ status: '' });
    pagination = new Pagination();

    nowD = new Date();



    constructor(
        private modal: ModalService,
        private inventoryService: InventoryService,
        private confirm: ConfirmService,
        public global: GlobalService,
    ) { }


    close() {
        this.modal.dismiss();
    }


    confirmSave(btn: any) {
        (this.inventory.id > 0 ? this.inventoryService.updatestage(this.inventory) : this.inventoryService.stageadd(this.inventory))
            .subscribe({
                next: () => this.modal.close(),
                complete: () => btn.dismiss()
            });
    }
    // testa() {
    //     this.voucherService.insertCompany(this.voucher).subscribe({
    //         next: res => {
    //             this.confirm.success('添加成功', `'${this.voucher.couponName}`);
    //             this.close();
    //             this.loadDatas();

    //         }
    //     });
    // }


}

